﻿using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CallCenter.Data;
using CallCenter.Data.BizUtilities;
using System.Configuration;
using System.Data;
using CallCenter.Security;
using CallCenter.Data.Models;
using CallCenter.Data.Misc;

namespace CallCenter.Web.Controllers
{
    public class CompanyContactsController : BaseController
    {
        // GET: CompanyContacts
        public ActionResult Index()
        {
            return View();
        }


        public ActionResult CompanyContactHistory()
        {
            CompanyContactsViewModel cmpy = new CompanyContactsViewModel();
            return View(cmpy);
        }

        public JsonResult GetCompanyContacts()
        {
            var scratchPads = this.Bridge.CompanyContactsUtility.GetCompanyContacts();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetAllContactCompany()
        {
            var scratchPads = this.Bridge.CompanyContactsUtility.GetAllContactsCompany();
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }


        public JsonResult GetAllCompany(CompanyContactsViewModel model ,int id)//CompanyContactsViewModel model, int id)
        {
           // model.companyId = 30;
            var scratchPads = this.Bridge.CompanyContactsUtility.GetAllCompany(id);
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public JsonResult CreateCompanyContacts(CompanyContactsViewModel model )
        {
            
            model.contactId = this.Bridge.ccContactUtility.GetContactIdByScName(model.name);
            var returnMessage = this.Bridge.CompanyContactsUtility.InsertToCompanyContact(model); ;          
            return Json(returnMessage, JsonRequestBehavior.AllowGet);  
        }

        [HttpPost]
        public JsonResult DeleteCompanyContact(CompanyContactsViewModel model)
        {
          
            int id = model.id;
            this.Bridge.CompanyContactsUtility.Delete(id);
            var returnMessage = "Success";
            return Json(returnMessage, JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        public JsonResult UpdateCompanyContact(CompanyContactsViewModel model)
        {

            model.contactId = this.Bridge.ccContactUtility.GetContactIdByScName(model.name);
            var result = this.Bridge.CompanyContactsUtility.UpdateToCompanyContact(model);
            return Json(result, JsonRequestBehavior.AllowGet);
        }




    }
}